<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/******************************************************
* Profile			: article 
* Author			: 乔伟
* Create Time		: 2011-10-05 
* Modify Time		: 2011-10-05 
* Modify Profile	:  
******************************************************/
class article extends Front_Controller {
	/******************************************************
	* Profile			: 列表
	* Author			: 乔伟
	* Create Time		: 2011-10-05 
	* Modify Time		: 2011-10-05
	* Modify Profile	:  
	******************************************************/ 
	public function index($class_id = null)
	{
		$where = $this->Request();  
		if($class_id!=null)
		{
			$where["class.id"] = trim(str_replace(".html", "", $class_id));  
		}
		// print_r($where) ;  exit ; 
		$class_alias = array_remove($where, 'class.alias');
		$class_id = array_remove($where, 'class.id');
		$article_class = null;
		if($class_id != null)
		{
			$article_class = $this->article_class_manager->get($class_id);
		}
		if($class_alias != null)
		{
			$article_class = $this->article_class_manager->get(array('alias'=>$class_alias));
		}

		$tpl_index = "v_index";
		$part_template = "";
		if($article_class!=null)
		{
			$part_template =  $article_class->part_template;
			if(!empty($part_template) && 
				file_exists(APPPATH."views/".$this->template."/".CONTROL_FOLDER."/article/v_".$part_template."_index.php"))
			{
				$tpl_index = "v_".$part_template."_index";
			}
		}  
		$this->load->view("front/article/$tpl_index",array('article_class'=>$article_class));    
	}

	/******************************************************
	* Profile			: 显示
	* Author			: 乔伟
	* Create Time		: 2011-10-05 
	* Modify Time		: 2011-10-05 
	* Modify Profile	:  
	******************************************************/
	public function show($id = null)
	{
		$id = isset($_GET['id'])?$this->input->get('id'):$id;
		$article = $this->article_manager->get($id);
		// $article->click();
		$tpl_show = "v_show";
		$part_template =  $article->class->part_template;
		if(!empty($part_template) && 
			file_exists(APPPATH."views/".$this->template."/".CONTROL_FOLDER."/article/v_".$part_template."_show.php"))
		{
			$tpl_show = "v_".$part_template."_show";
		}
		$this->load->view("front/article/$tpl_show",array('article'=>$article));  
	} 
}
